package com.ctrip.ec.api.mobile.controller;

import com.ctrip.ec.api.mobile.common.JsonBody;
import com.ctrip.ec.biz.dao.invite.InviteCodeDao;
import com.ctrip.ec.biz.entity.invite.InviteCodeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by jiangzy on 2018/11/13.
 */
@RestController
@RequestMapping("inviteCode")
public class InviteCodeController {

    @Autowired
    private InviteCodeDao inviteCode;

    @GetMapping("list")
    @JsonBody(false)
    public List<String> list() throws SQLException {
        List<InviteCodeEntity> list = inviteCode.listTopUnUse(100);
        return list.stream().map(t->t.getCode()).collect(Collectors.toList());
    }
}
